package com.zx.map.dao.impl;

import com.zx.map.dao.NoticeLogDao;
import com.zx.map.dao.mapper.NoticeLogMapper;
import com.zx.map.dao.model.NoticeLog;
import com.zx.map.dao.model.NoticeLogExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 14-3-1
 * Time: 上午10:54
 * To change this template use File | Settings | File Templates.
 */
@Component("noticeLogDao")
public class NoticeLogImpl implements NoticeLogDao {

    @Autowired
    private NoticeLogMapper mapper;

    /**
     * 新增
     */
    public String add(NoticeLog noticeLog) throws DataAccessException {
        int column = mapper.insert(noticeLog);
        if (column != 1) {
            throw new RuntimeException("");
        }
        return noticeLog.getNoticeId().toString();
    }

    /**
     * 修改
     *
     * @param noticeLog
     * @return
     * @throws DataAccessException
     */
    public String update(NoticeLog noticeLog) throws DataAccessException {
        int column = mapper.updateByPrimaryKeySelective(noticeLog);
        if (column != 1) {
            throw new RuntimeException("");
        }
        return noticeLog.getNoticeId().toString();
    }

    /**
     * 删除
     */
    public void delete(NoticeLog noticeLog) throws DataAccessException {
        int column = mapper.deleteByPrimaryKey(noticeLog.getNoticeId());
        if (column != 1) {
            throw new RuntimeException("");
        }
    }

    /**
     * 分页查找
     */
    public List<NoticeLog> getPageByExample(int pageSize, int pageBegin,
                                            NoticeLogExample example) throws DataAccessException {
        return mapper.getPageByModel(pageSize, pageBegin, example);
    }


    /**
     * 分页查找
     */
    public List<NoticeLog> getListByExample(NoticeLogExample example) throws DataAccessException {
        return mapper.selectByExample(example);
    }

    /**
     * 查找条数
     *
     * @param example
     * @return
     * @throws DataAccessException
     */
    public int countByExample(NoticeLogExample example) throws DataAccessException {
        return mapper.countByExample(example);
    }

}
